package com.chixing.entity;


import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *
 * </p>
 *
 * @author liwenjing
 * @since 2025-10-07
 */
@Data
@Document(collection = "comments") // MongoDB 集合名
public class Comment  {

    @Id
    private String id;


    /** 电影ID */
    @Field("movie_id")
    private String movieId;


    /** 发布者用户ID */
    @Field("user_id")
    private String userId;

    /** 用户名称 */
    @Field("user_name")
    private String userName;


    /** 父评论ID（顶层评论为 null） */
    @Field("parent_id")
    private String parentId;


    /** 评论内容 */
    private String content;

    private String movieName;
    /** 点赞数 */
    private int likes;


    /** 创建时间（ISO-8601 epoch millis） */
    @Field("create_time")
    private long createTime;


    // 仅用于 API 输出：子评论列表（不持久化为树，仍保存在同集合中）
    private List<Comment> children = new ArrayList<>();


    public Comment() {}


    public Comment(String movieId, String userName, String userId, String parentId,String movieName, String content) {
        this.movieId = movieId;
        this.userId = userId;
        this.userName = userName;
        this.parentId = parentId;
        this.movieName = movieName;
        this.content = content;
        this.createTime = Instant.now().toEpochMilli();
        this.likes = 0;
    }


// getters / setters


    public String getId() { return id; }
    public void setId(String id) { this.id = id; }


    public String getMovieId() { return movieId; }
    public void setMovieId(String movieId) { this.movieId = movieId; }


    public String getUserId() { return userId; }
    public void setUserId(String userId) { this.userId = userId; }


    public String getParentId() { return parentId; }
    public void setParentId(String parentId) { this.parentId = parentId; }

    public String getMovieName() {
        return movieName;
    }

    public void setMovieName(String movieName) {
        this.movieName = movieName;
    }

    public String getContent() { return content; }
    public void setContent(String content) { this.content = content; }


    public int getLikes() { return likes; }
    public void setLikes(int likes) { this.likes = likes; }


    public long getCreateTime() { return createTime; }
    public void setCreateTime(long createTime) { this.createTime = createTime; }


    public List<Comment> getChildren() { return children; }
    public void setChildren(List<Comment> children) { this.children = children; }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }
}
